/*	$Id: buf.h 1116 2010-12-12 20:56:04Z phrakt $	*/
/*	$OpenBSD: buf.h,v 1.22 2007/02/22 06:42:09 otto Exp $	*/
/*
 * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES       (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _CANOPY_BUF_H_
#define _CANOPY_BUF_H_

#include <sys/types.h>

#include <stdint.h>

#include <canopy/cdefs.h>

/* flags */
#define CNP_BUF_AUTOEXT		1	/* autoextend on append */

typedef struct cnp_buf cnp_buf_t;


cnp_buf_t*     cnp_buf_alloc    (size_t, unsigned int);
cnp_buf_t*     cnp_buf_load     (const char *, off_t, unsigned int);
cnp_buf_t*     cnp_buf_loadfd   (int, off_t, unsigned int);
void           cnp_buf_free     (cnp_buf_t *);
int            cnp_buf_resize   (cnp_buf_t *, size_t);
uint8_t*       cnp_buf_unwrap   (cnp_buf_t *);
int            cnp_buf_getc     (cnp_buf_t *);
int            cnp_buf_ungetc   (cnp_buf_t *, int);
void           cnp_buf_empty    (cnp_buf_t *);
ssize_t        cnp_buf_find     (cnp_buf_t *, size_t, const uint8_t *, size_t);
ssize_t        cnp_buf_append   (cnp_buf_t *, const void *, size_t);
ssize_t        cnp_buf_fappend  (cnp_buf_t *, const char *, ...)
					ATTR_FORMAT(2, 3);
int            cnp_buf_setc     (cnp_buf_t *, size_t, int);
int            cnp_buf_putc     (cnp_buf_t *, int);
size_t         cnp_buf_len      (cnp_buf_t *);
int            cnp_buf_cmp      (const cnp_buf_t *, const cnp_buf_t *);
ssize_t        cnp_buf_copy     (cnp_buf_t *, size_t, void *, size_t);
const uint8_t* cnp_buf_peek     (cnp_buf_t *, size_t);
int            cnp_buf_write    (cnp_buf_t *, const char *, mode_t);
int            cnp_buf_writefd  (cnp_buf_t *, int);


#endif	/* _CANOPY_BUF_H_ */
